package com.sxg.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxg.convert.SxgOrderItemConvert;
import com.sxg.dao.SxgOrderItemDao;
import com.sxg.entity.SxgOrderItemEntity;
import com.sxg.query.SxgOrderItemQuery;
import com.sxg.service.SxgOrderItemService;
import com.sxg.vo.SxgOrderItemVO;
import lombok.AllArgsConstructor;
import com.sxg.page.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 订单商品表
 *
 * @author 浪漫写尽歌谱 3298751420@qq.com
 * @since 1.0.0 2024-03-07
 */
@Service
@AllArgsConstructor
public class SxgOrderItemServiceImpl extends ServiceImpl<SxgOrderItemDao, SxgOrderItemEntity> implements SxgOrderItemService {

    @Override
    public PageResult<SxgOrderItemVO> page(SxgOrderItemQuery query) {
        IPage<SxgOrderItemEntity> page = baseMapper.selectPage(PageResult.getPage(query), getWrapper(query));

        return new PageResult<>(SxgOrderItemConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<SxgOrderItemEntity> getWrapper(SxgOrderItemQuery query){
        LambdaQueryWrapper<SxgOrderItemEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(SxgOrderItemVO vo) {
        SxgOrderItemEntity entity = SxgOrderItemConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(SxgOrderItemVO vo) {
        SxgOrderItemEntity entity = SxgOrderItemConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}